<template>
  <div class="tbox">
    <div class="back" @click="toaddress">
      <i class="el-icon-close"></i>添加地址
    </div>
    <div style="margin: 20px;"></div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="联系人">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="" prop="resource">
        <el-radio-group v-model="form.sex">
          <el-radio label="先生"></el-radio>
          <el-radio label="女士"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="电 话">
        <el-input v-model="form.number"></el-input>
      </el-form-item>
      <el-form-item label="地 址" >
        <el-amap-search-box class="search-box"
                            :search-option="form.searchOption"
                            :on-search-result="onSearchResult"
        >
        </el-amap-search-box>
      </el-form-item>
      <el-form-item label="门牌号">
        <el-input v-model="form.door"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="toaddress(form)" style="width: 90%;margin: auto;">立即创建</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  export default {
    name: 'addAddress',
    data () {
      return {
        labelPosition: 'left',
        form: {
          name: '',
          door: '',
          flag: true,
          type: [],
          sex: '',
          address: '',
          number: '',
          searchOption: {
            city: this.$store.state.city,
            citylimit: true
          }
        }
      }
    },
    methods: {
      toaddress (form) {
        console.log(form)
        this.$store.dispatch('changeAddress', form)
        this.$router.push('/address')
      },
      onSearchResult (pois) {
       // console.log(pois[0].name)
        this.form.address = pois[0].name
      }
    }
  }
</script>
<style lang="stylus" type="text/stylus" scoped>
  @import '../../common/stylus/mixin.styl'
  .tbox
    width :100%
    overflow :hidden
    .back
      width :100%
      height :40px
      background-color :blue
      line-height :40px
      color :white
      padding-left :10px
      font-size :14px
      i
        margin-right :20px
        font-size :18px

</style>
